﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using log4net;

namespace IdCardApp
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {            //加载日志配置
            log4net.Config.XmlConfigurator.Configure();

            //处理UI线程异常
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            //处理非UI线程异常
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            ILog log = log4net.LogManager.GetLogger("root");

            log.Error(e.Exception.Message, e.Exception);
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            ILog log = log4net.LogManager.GetLogger("root");

            Exception ex = e.ExceptionObject as Exception;

            if (ex != null)
            {
                log.Error(ex.Message, ex);
            }
            else
            {
                log.Error(e.ExceptionObject);
            }
        }
    }
}
